/*****************************************************
Copyright (C) 2020. All rights reserved.
File name     ：TestMain.c
Version       ：v1.0
Author        ：zhengqijun
Date          ：2020-05-04
Function List ：
Description   ：main function
******************************************************/

#include <stdio.h>  // for printf
#include "BTree.h"

// main function
int main(void) {
    BTree T = NULL;

    T = MakeEmpty(T);

    if (IsEmpty(T)) {
        printf("BTree is empty!\n");
    } else {
        printf("BTree is not empty!\n");
    }

    {  /* Insert */
        T = Insert(3, T);
        T = Insert(5, T);
        T = Insert(7, T);
        T = Insert(9, T);
        T = Insert(1, T);
        T = Insert(4, T);
        T = Insert(11, T);
        T = Insert(17, T);
        T = Insert(19, T);
        T = Insert(22, T);
        T = Insert(23, T);
        T = Insert(28, T);
    }

    printf("Insert b-tree: [ 3 5 7 9 1 4 11 17 19 22 23 28 ]\n");
    if (IsEmpty(T)) {
        printf("BTree is empty!\n");
    } else {
        printf("BTree is not empty!\n");
    }

    printf("Print b-tree:\n");
    PrintBTree(T);
    printf("\n");

    printf("Min is %02d in the b-tree\n", RetrieveMin(FindMin(T)));
    printf("Max is %02d in the b-tree\n", RetrieveMax(FindMax(T)));

    if (IsEmpty(Find(5, T))) {
        printf("Can not find element 5 in the b-tree\n");
    } else {
        printf("Find element 5 in the b-tree\n");
    }

    printf("Delete element 5 in the b-tree\n");
    T = Delete(5, T);

    if (IsEmpty(Find(5, T))) {
        printf("Can not find element 5 in the b-tree\n");
    } else {
        printf("Find element 5 in the b-tree\n");
    }

    if (IsEmpty(Find(19, T))) {
        printf("Can not find element 19 in the b-tree\n");
    } else {
        printf("Find element 19 in the b-tree\n");
    }

    printf("Print b-tree:\n");
    PrintBTree(T);
    printf("\n");

    printf("Delete element 4 in the b-tree\n");
    T = Delete(4, T);

    printf("Print b-tree:\n");
    PrintBTree(T);
    printf("\n");
    
    printf("Delete element 19 in the b-tree\n");
    T = Delete(19, T);

    printf("Print b-tree:\n");
    PrintBTree(T);
    printf("\n");

    printf("Delete element 28 in the b-tree\n");
    T = Delete(28, T);

    printf("Print b-tree:\n");
    PrintBTree(T);
    printf("\n");

    printf("Delete element 9 in the b-tree\n");
    T = Delete(9, T);

    printf("Print b-tree:\n");
    PrintBTree(T);
    printf("\n");

    printf("Delete element 11 in the b-tree\n");
    T = Delete(11, T);

    printf("Print b-tree:\n");
    PrintBTree(T);
    printf("\n");

    T = MakeEmpty(T);

    return 0;
}

// EOF

